<!DOCTYPE html>
<html lang="en">
<head>
    <title>购买保险</title>
    <style type="text/css">
        input[id="i-name"].error, input[id="l-name"].error {
            border: 1px solid red;
        }
    </style>
</head>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script src="/js/layer/layer.js" charset="utf-8"></script>
<body>
<section id="container">
<#include "sider.ftl">  <#--引入头部和导航栏-->
    <section id="main-content">
        <section class="wrapper">
            <div class="form-w3layouts">
                <!-- page start-->
                <div class="row">
                    <div class="col-lg-12">
                        <section class="panel">
                            <header class="panel-heading">
                                保险缴费
                                <span class="tools pull-right">
                                <a class="fa fa-chevron-down" href="javascript:;"></a>
                                <a class="fa fa-cog" href="javascript:;"></a>
                                <a class="fa fa-times" href="javascript:;"></a>
                             </span>
                            </header>
                            <div class="panel-body" style="width: 1000px; margin: 0 auto;">
                                <form class="form-horizontal" id="updateForm">
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*客户证件号：</label>
                                        <div class="col-lg-6">
                                            <input type="text" id="i-name" value="${order.user.scardId}" disabled
                                                    class="form-control">
                                            <span id="cardmsg"></span>
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*车牌号：</label>
                                        <span id="msgcarid"></span><span id="msg"></span>
                                        <div class="col-lg-6">
                                            <input type="text" id="l-name" value="${order.cars.licenseNum}"
                                                   disabled class="form-control">
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*保险套餐：</label>
                                        <div class="col-lg-6">
                                            <table class="table table-striped" border="1px" width="300px" id="combo">
                                                <tr>
                                                    <td>选择</td>
                                                    <td>套餐类型</td>
                                                    <td>所含保险</td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">应付金额：</label>
                                        <div class="col-lg-6">
                                            <input type="text" id="m-name" value="${order.paymoney}" name="paymoney" class="form-control">
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*支付状态：</label>
                                        <div class="col-lg-6">
                                            <select name="paystate" id="paystate" class="form-control">
                                                <option value="0">未缴费</option>
                                                <option value="1">已缴费</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*支付方式：</label>
                                        <div class="col-lg-6">
                                            <select name="paymethod" id="paymethod" class="form-control">
                                                <option value="0"> 未缴费</option>
                                                <option value="1">支付宝</option>
                                                <option value="2">微信</option>
                                                <option value="3">现金</option>
                                                <option value="4">银行卡</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">备注：</label>
                                        <div class="col-lg-6">
                                            <textarea class="form-control" id="oremark" name="oremark"
                                                      style="width: 480px;height: 100px">${order.oremark}</textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-lg-offset-3 col-lg-6">
                                            <button class="btn btn-primary" type="button" id="submitBtn">提交</button>
                                            <button class="btn btn-default" type="button" id="returnPre">&gt;返回</button>
                                        </div>
                                    </div>
                                    <input type="hidden" id="ouid" name="ouid" value="${order.ouid}">
                                    <input type="hidden" id="oid" name="oid" value="${order.oid}">
                                    <input type="hidden" id="addtime" name="addtime" value="${order.addtime}">
                                    <input type="hidden" id="uid" name="uid" value="${order.user.suId}">
                                    <input type="hidden" id="caruid" name="caruid" value="${order.cars.carUuid}">
                                </form>
                            </div>
                        </section>
                    </div>
                </div>
            </div>
        </section>
    <#include "/foot.html"><#--引入底部-->
    </section>
</section>
</body>
</html>
<script type="text/javascript">
    ////加载套餐 以及包含的所有保险
    $.ajax({
        url: "/order/getAllCombo.do",
        dataType: "json",
        type: "post",
        success: function (data) {

            $.each(data, function (index, obj) {
                /* console.log(obj);*/
                var newtr = " <tr><td><input type='checkbox' value='" + obj.comuuid + "' id='" + obj.comuuid + "' class='combotype' name='combo'></td><td width='100px'>" + obj.combname + "</td><td><table class='" + obj.comuuid + "'></table></td></tr>";
                $("#combo").append(newtr);
                $.each(obj.list, function (index, object) {
                    var newtable = "<tr><td>" + object.insurname + "</td></tr>";
                    $("." + obj.comuuid + "").append(newtable);
                })
            })
            /////复选框默认选中
            $("#${order.combo.comuuid}").prop("checked", true);
        }
    });
    /////点击返回按钮
    $("#returnPre").click(function () {
        window.history.back(-1);
    });
    $("#submitBtn").click(function () {
        $.ajax({
            url:"/order/updatePaystate.do",
            type:"post",
            dataType:"json",
            data:{
                ouid:$("#ouid").val(),
                oid:$("#oid").val(),
                addtime:$("#addtime").val(),
                paystate:$("#paystate").val(),
                paymethod:$("#paymethod").val(),
                paymoney:$("#m-name").val(),
                comuuid:$("input[type=checkbox]:checked").val(),
                caruid:$("#caruid").val(),
                uid:$("#uid").val(),
                oremark:$("#oremark").val()
            },
            success:function (data) {
                if (data==true){
                    layer.msg("成功缴费，订单开始生效...", {icon: 6});
                    ////2s之后跳转
                    setTimeout("location.href='/order/toOrderQuery.do'", 2000);
                }else{
                    layer.msg("缴费失败，请刷新重试", {icon: 5});
                }
            }
        });
    });
</script>